<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function Person(name, age) {
      this.name = name
      this.age = age
    }
    Person.prototype.running = function () {
      console.log("running~")
    }
    Person.prototype.eating = function () {
      console.log("eating~")
    }
    var p1 = new Person("why", 18)
    var p2 = new Person("kobe", 30)
    p1.running()

    // 没有实例对象的时候,无法调用
    // Person.running()
    console.log(Person.__proto__ === Function.prototype)

    // 类方法
    var names = ["abc", "cba", "nba", "mba"]
    Person.randomPerson = function() {
      var randomName = names[Math.floor(Math.random() * names.length)]
      return new Person(randomName, Math.floor(Math.random() * 100))
    }
    var p = Person.randomPerson()
    console.log(p)

  </script>
</body>

</html>